package com.ebc.eservice.config.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2   //开启swagger
public class SwaggerConfig {
    //配置bean实例 docket
    @Bean
    public Docket docket(Environment environment){
        //选择环境
        Profiles profiles = Profiles.of("dev");
        boolean flag =environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("PC") //分组名
                .enable(flag) // 配置启动开关
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ebc.eservice.controller.pc")) //指定扫描的接口文件  其他看typora
//                .paths(PathSelectors.ant("/com/**"))//过滤扫描 不让swagger扫描到
                .build();
    }
    @Bean
    public Docket docket2(Environment environment){
        Profiles profiles = Profiles.of("dev");
        boolean flag =environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo2())
                .groupName("App")
                .enable(flag) // 配置启动开关
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ebc.eservice.controller.app")) //指定扫描的接口文件  其他看typora
//                .paths(PathSelectors.ant("/com/**"))//过滤扫描 不让swagger扫描到
                .build();
    }
    //配置swagger 信息
    private ApiInfo apiInfo(){
        //作者
        Contact contact = new Contact("3组-名片小程序PC端","[url]","x-jan@outlook.com");
        return new ApiInfo("Pc端-api文档",
                "@Author: fuHao &   \n" +
                        "使用GET & POST,接口请求参数大部分采用@RequestBody,所有接口访问权限暂时放开,无需登录认证",
                "2.3",
                "[url]",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
    private ApiInfo apiInfo2(){
        //作者
        Contact contact = new Contact("3组-名片小程序app端","http://47.108.218.56:8080/appCloud/","x-jan@outlook.com");
        return new ApiInfo("App端-api文档",
                "@author: fuHao & \n" +
                        "所有接口访问权限暂时放开,无需登录认证",
                "2.0",
                "http://47.108.218.56:8080/app-4/",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
